package com.sunlee.common.core.utils;


import cn.hutool.core.util.ArrayUtil;
import com.sunlee.common.core.enums.ErrorCodeEnum;
import com.sunlee.common.core.exception.BusinessException;
import org.apache.commons.lang3.StringUtils;

/**
 * 校验工具类
 *
 * @author sunlee
 */
public class AssertUtils {
    private AssertUtils() {
    }

    public static void isBlank(String str, String params) {
        if (StringUtils.isBlank(str)) {
            throw new BusinessException(ErrorCodeEnum.PARAMETER_ERROR.format(params + "不能为空"));
        }
    }

    public static void isBlank(String str, ErrorCodeEnum errorCodeEnum) {
        if (StringUtils.isBlank(str)) {
            throw new BusinessException(errorCodeEnum);
        }
    }

    public static void isNull(Object object, String params) {
        if (object == null) {
            throw new BusinessException(ErrorCodeEnum.PARAMETER_ERROR.format(params + "不能为空"));
        }
    }


    public static void isArrayEmpty(Object[] array, String params) {
        if (ArrayUtil.isEmpty(array)) {
            throw new BusinessException(ErrorCodeEnum.PARAMETER_ERROR.format(params + "不能为空"));
        }
    }
}